#
# @lc app=leetcode.cn id=530 lang=python3
#
# [530] 二叉搜索树的最小绝对差
#
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
# @lc code=start
# Definition for a binary tree node.
class Solution:
    def getMinimumDifference(self, root: TreeNode) -> int:
        if root is None:
            return None
        nums = []
        self.inorder(root, nums)
        pre_val = nums[0]
        min_val = float("inf")
        for i in range(1, len(nums)):
            min_val = min(nums[i] - pre_val, min_val) 
            pre_val = nums[i]
        return min_val
    
    def inorder(self, root, nums):
        if root is None:
            return
        self.inorder(root.left, nums)
        nums.append(root.val)
        self.inorder(root.right, nums)

# @lc code=end

